package cl.mybatis.dao.test;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import cl.mybatis.dao.StudentMapper;
import cl.mybatis.entity.Student;
import cl.mybatis.entity.Teacher;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/spring-mybatis.xml")
public class StudentDao {

	@Resource
	private StudentMapper studentDao;

	@Test
	public void testAdd() {
		Student s1 = new Student();
		// for (int i = 1; i < 10001; i++) {
		int i = 10005;
		s1.setId(i);
		s1.setGrade(1);
		s1.setName("呵呵" + i);
		List<Teacher> ts = new ArrayList<Teacher>();
		ts.add(new Teacher(1));
		s1.setTeachers(ts);
		studentDao.insert(s1);
		// }
	}

	@Test
	public void insertTeachers() {
		Student s = new Student();
		s.setName("嘻嘻");
		s.setGrade(1);
		s.setId(12312312);
		List<Teacher> ts = new ArrayList<Teacher>();
		ts.add(new Teacher(2));
		ts.add(new Teacher(3));
		ts.add(new Teacher(4));
		ts.add(new Teacher(6));
		s.setTeachers(ts);
		studentDao.insertStudent(s);

	}
}
